<?php

require_once './include/common.inc.php';
require_once './include/country.php';
require_once 'left.php';
require_once 'right.php';

$page_title = 'Acuity World WebShop';
$menu_id = 0;
$menu_str = PrintMenu();
$alert_message = '';
$jsFile = '<script src="css/memberSignUp.js" type="text/javascript" language="javascript"></script>';
$countryStr1 = FFPCountry("Denmark","country");
$countryStr2 = FFPCountry("Denmark","country2");

$act = $_POST['act'];

if ($act == "" && isLogin()) {
    header("Location: shopping_cart.php?checkout");
    exit;
}



if ($act == "login") {
    $email = $_POST['email'];
    $password = $_POST['password']; 
	$rememberEmail = $_POST["rememberEmail"];
	$signupCookieTime = $rememberEmail == 1 ? time()+3600*24*30: time()+3600;
    
    if(!empty($email) && !empty($password)){
        $rs = $db->get_one("SELECT * FROM `cus_members` WHERE `email`='" . $email . "'");
        
        if($rs && md5($password) == $rs['password1']){
			//clear all cookies  and session first
			if(isPromoterLogin())
			{
				Cookie('webshoppromoter','',0);
			}  
				
            Cookie("webshopuser",base64_encode($rs['id']."\t".$rs['email']."\t".$timestamp),$signupCookieTime);
			Cookie("myCart_signdate",$rs["date"],$signupCookieTime);
            header("Location: shopping_cart.php?checkout");
            exit;
        } else {
            $alert_message = "Invalid email or password! Please try again.";
        }
    } else {
        $alert_message = "Please enter your email and password to login.";
    }
    
    if ($alert_message != '' && false) {
        echo '<script>alert("' . $alert_message . '");history.back(1);</script>';
        exit;
    }
    
} elseif ($act == "logout") {
    Cookie('webshopuser','',0);
    header("Location: member_signup.php");
    exit;
} 



require_once PrintEot('header');
require_once PrintEot('left');
require_once PrintEot('member_signup');
require_once PrintEot('right');
require_once PrintEot('footer');

?>